
if(sessionStorage.getItem("noticeEdittitle")=="编辑"){
    querydatas()
}

function querydatas() {
    $.ajax({
        url:root.member.findCustomerBulletinById ,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        data:{
            "id":sessionStorage.getItem("noticeids"),

        },
        success: function (data) {
            if(data.errorCode==0){
                $("#title").val(data.data.title)
                $("#displaySequence").val(data.data.displaySequence)
                $("#createTime").val(data.data.startTime)
                $("#createTimeEnd").val(data.data.endTime)
                if(data.data.richText!=""&&data.data.richText!=null){
                    ue.ready(function() {
                        ue.setContent(data.data.richText);
                    });
                }
                if(data.data.status==0){
                    $("#picStatus1").prop("checked",true);
                }else if(data.data.status==1){
                    $("#picStatus2").prop("checked",true);
                }


            }else {
                $.Huimodalalert(data.msg,2000);
            }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}


//保存
function addcarouselMap() {
    ue.ready(function() {
        text = ue.getContent();
    });
    if($("#title").val()==""){
        $.Huimodalalert("请编辑标题",2000);
        return false;
    }

    if($("#displaySequence").val()==""){
        $.Huimodalalert("请编辑展示顺序",2000);
        return false;
    }
    if($("#createTime").val()=="" && $("#createTimeEnd").val()==""){
        $.Huimodalalert("请编辑生效时间",2000);
        return false;
    }
    if(text==""){
        $.Huimodalalert("请编辑文章内容",2000);
        return false;
    }
    if($("input[name=picStatus]:checked").val()==undefined){
        $.Huimodalalert("请编辑生效状态",2000);
        return false;
    }
    var noticeids=""
    var carouselmapurl=""
    if(sessionStorage.getItem("noticeEdittitle")=="添加"){
        carouselmapurl=root.member.addCustomerBulletin
        noticeids=""
    }else {
        carouselmapurl=root.member.updateCustomerBulletin
        noticeids=sessionStorage.getItem("noticeids")
    }


    $.ajax({
        url:carouselmapurl,
        cache: false,  //禁用缓存
        type: "POST",
        dataType:'json',
        contentType: "application/json",
        data: JSON.stringify({
            "id":noticeids,
            "mainCustomerId":sessionStorage.getItem("noticeEditCustomerIds"),
            "title":$("#title").val(),
            "displaySequence":$("#displaySequence").val(),
            "startTime":$("#createTime").val(),
            "endTime":$("#createTimeEnd").val(),
            "richText":text,
            "status":$("input[name=picStatus]:checked").val(),
            "isDelete":0,
        }),
        success: function (data) {
                    if(data.errorCode==0){
                        if(sessionStorage.getItem("noticeEdittitle")=="添加"){
                            layer.msg('添加成功', {icon: 6, time: 1000});
                            setTimeout(function () {
                                window.parent.noticequery();
                                var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                                parent.layer.close(index);
                            }, 1000)
                        }else {
                            layer.msg('编辑成功', {icon: 6, time: 1000});
                            setTimeout(function () {
                                window.parent.noticequery();
                                var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
                                parent.layer.close(index);
                            }, 1000)
                        }

                    }else {
                        $.Huimodalalert(data.msg,2000);
                    }

        },
        error: function () {
            $.Huimodalalert('失败！',2000);
        }
    });
}
//取消
function cancelbtn() {
    var index = parent.layer.getFrameIndex(window.name);  // 关闭当前页面，并不刷新父级页面
    parent.layer.close(index);
}
